unit StdVarChartUnit;

interface


uses DiagramFactory, datacontainer, pganalysistypesunit, apgabstractunit, classes,
   xmlintf, pgseriesunit, chartaxisunit, ifmmemoryunit, math, sysutils;


type
   StdVarChart = class(TasacsChart)
   private
      m_Var : StdVar;
   protected
   public
      function CreateChartAxis(Axis : PgAxisType) : APgChartAxis; override;
      function CreateSeries(AOwner : TComponent; PrimaryChartAxis : APgChartAxis; MetaSeries : APgMetaSeries; XIndex : Integer) : APgSeries; override;
      constructor Create(AOwner : TComponent; ItemNode : IXMLNode; Caption : string; _Var : StdVar; datacontainer : TasacsDataContainer); reintroduce;
      property _Var : StdVar read m_Var;
   end; // StdVarChart


   StdDiagram = class(TasacsDiagram)
   public
      constructor Create(AOwner : TComponent; datacontainer : TasacsDataContainer); reintroduce;
   end;


   StdVarSeries = class(PgSeries)
   protected
      function GetInternalValue(I : Integer; SeriesVariable : PgSeriesVariable; MetaSeries : ApgMetaSeries) : Double; override;
   end; // StdVarSeries


implementation


///////////////////////
// StdVarChart


function StdVarChart.CreateChartAxis(Axis : PgAxisType) : APgChartAxis;
begin
   case Axis of
      atx:
         Result := StdYearAxis.Create(Self as IChart, Axis);
   else
      Result := PgChartAxis.Create(Self as IChart, Axis);
   end; // case
end; // StdVarChart.CreateChartAxis


function StdVarChart.CreateSeries(AOwner : TComponent; PrimaryChartAxis : APgChartAxis; MetaSeries : APgMetaSeries; XIndex : Integer) : APgSeries;
begin
   Result := nil;
   case PrimaryChartAxis.axis of
      atX:
         if Assigned(MetaSeries) then
           Result := StdVarSeries.Create(AOwner, PrimaryChartAxis, MetaSeries, XIndex)
         else
            Result := StdYearAxisSeries.Create(AOwner, PrimaryChartAxis, MetaSeries, XIndex);
   end; // case
end; // StdVarChart.CreateSeries


constructor StdVarChart.Create(AOwner : TComponent; ItemNode : IXMLNode; Caption : string; _Var : StdVar; datacontainer : TasacsDataContainer);
var
   M : APgMetaSeries;
   seriesname : string;
begin
   m_Var := _Var;
   inherited Create(AOwner, ItemNode, 'Chart', datacontainer);
   Self.Caption := Caption;
   ChartLegend := Caption;
   self.ShowChartLegend := false;
   if not Assigned(ItemNode) then
   begin
      ShowSeriesLegend := false;
      ShowMeanLegend := false;
//      ChartAxis[atX].ShowIntervalSeries := true;
      PlotType := ptCategorySingle;

      chartaxis[atX].ContinuousGroupData := false;
      chartaxis[atX].ShowMinorTick := false;
      chartaxis[atX].AxisLine := true;
      chartaxis[atX].ShowTickText := true;
      chartaxis[atX].ShowMajorTick := true;
      //chartaxis[atX].AxisLabelPosition := alpCenter;
      chartaxis[atX].ShowMajorGrid := true;
      seriesname := floatarray(datacontainer.StdData[integer(m_Var)]).ArrayName;
      chartaxis[aty].ShowLabel := true;
      chartaxis[aty].AxisLabel := Caption;
      chartaxis[aty].AxisLabelPosition := alpCenter;
      chartaxis[atY].ShowMajorGrid := true;
      chartaxis[aty].ShowMajorTick := true;
      chartaxis[aty].ShowMinorTick := false;
      chartaxis[aty].ShowTickText := true;
      chartaxis[aty].AxisLine := true;
      chartaxis[aty].DefaultAxisLabel := false;
      chartaxis[aty].DefaultMin := false;
      chartaxis[aty].MinValue := 0;
      // Setup meta series at y axis:
      with ChartAxis[atY].MetaSeries do
      begin
         M := TasacsMetaSeries.Create(ChartAxis[aty], nil, Self.Caption, 0);
         Add(Pointer(M));
         M.BarPlot := false;
         M.Scatter := true;
         M.LinePlot := true;
      end;
   end;
end; // StdVarChart.Create


///////////////////////////////
// StdDiagram


constructor StdDiagram.Create(AOwner : TComponent; datacontainer : TasacsDataContainer);
begin
   inherited Create(AOwner, nil, '', 'Standard plots', 'Summary from model results', datacontainer);
   NumDiagramColumns := 1;
   UseDefDiagramColumns := false;
end; // StdDiagram.Create


///////////////////////////////
// StdVarSeries


function StdVarSeries.GetInternalValue(I : Integer; SeriesVariable : PgSeriesVariable; MetaSeries : ApgMetaSeries) : Double;
begin
   case SeriesVariable of
      svIntervalDelta:
         with TasacsChart(PrimaryChartAxis.ChartComp).Datacontainer do
         with StdVarChart(PrimaryChartAxis.ChartComp) do
            Result := FloatArray(StdData[integer(_Var)])[PgChartAxis(ChartAxis[atX]).Series.MinCategory + I];
   else
      Result := inherited GetInternalValue(I, SeriesVariable, MetaSeries)
   end; // case
end; // StdVarSeries.GetInternalValue


end.
